package cn.lzm.org.service.impl;

import cn.lzm.basic.service.impl.BaseServiceImpl;
import cn.lzm.org.domain.SystemDictionaryDetail;
import cn.lzm.org.domain.SystemDictionaryType;
import cn.lzm.org.mapper.SystemDictionaryDetailMapper;
import cn.lzm.org.mapper.SystemDictionaryTypeMapper;
import cn.lzm.org.service.ISystemDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SystemDictionaryTypeServiceImpl extends BaseServiceImpl<SystemDictionaryType> implements ISystemDictionaryTypeService {
    @Autowired
    private SystemDictionaryTypeMapper systemDictionaryTypeMapper;
    @Autowired
    private SystemDictionaryDetailMapper systemDictionaryDetailMapper;
    @Override
    public void deleteALL(Long id) {
        List<SystemDictionaryDetail> all = systemDictionaryDetailMapper.findByTypesIdSystemDictionaryDetails(id);
        if (!all.isEmpty()){
            ArrayList<Long> ids = new ArrayList<>();
            for (SystemDictionaryDetail systemDictionaryDetail : all) {
                ids.add(systemDictionaryDetail.getId());
            }
            systemDictionaryDetailMapper.batchDelete(ids);
         }
        systemDictionaryTypeMapper.delete(id);
    }
}
